package org.wmq.shopmanager.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.commonutil.result.Result;
import org.wmq.shopmanager.service.SystemMenuService;
import org.wmq.shopmodel.Entity.system.SystemMenu;

import java.util.List;

@RestController
@RequestMapping("/admin/system/system-menu")
@RequiredArgsConstructor
public class SystemMenuController {
    private final SystemMenuService systemMenuService;

    @GetMapping("/getNodes")
    public Result<List<SystemMenu>> getNodes(){
        return Result.success(this.systemMenuService.getNodes());
    }

    @PostMapping
    public Result<Void> saveSystemMenu(@RequestBody SystemMenu systemMenu){
        this.systemMenuService.save(systemMenu);
        return Result.success();
    }

    @PutMapping
    public Result<Void> updateSystemMenuById(@RequestBody SystemMenu systemMenu){
        this.systemMenuService.updateById(systemMenu);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> removeSystemMenuById(@PathVariable Long id){
        return this.systemMenuService.removeById(id);
    }
}
